<template>
	<view class="capital">
		<view class="box">
			<user-money :show="show"></user-money>
			<block-title :title="'资金往来记录'"></block-title>
		</view>
		<scroll-view scroll-y="true" :style="{height: screenHeight+'upx'}" @scrolltolower="getData()">
			<view class="list" v-for="(item,index) of data" :key="index">
				<view class="list-left">
					<text>{{currencyType(item.type)}}</text>
					<text>{{formatDate(item.create_time*1000)}}</text>
				</view>
				<view class="list-right">
					<text :class="item.status===1?'add':'reduce'">{{item.status===1?'+':'-'}}{{item.currency}}</text>
				</view>
			</view>
			<block-loading :status="status" :len="data.length"></block-loading>
		</scroll-view>
	</view>
</template>

<script>
	import userMoney from"../components/UserMoney/UserMoney.vue"
	import BlockTitle from "@/components/BlockTitle/BlockTitle.vue"
	import {currencyType,formatDate} from "@/utils/util.js"
	import {
		recordCurrency
	} from '@/api/record.js';
	export default{
		name:"capital",
		components:{
			userMoney,
			BlockTitle
		},
		data(){
			return{
				screenHeight:0,
				data:[],
				status:"loading",
				show:false,
				page:1
			}
		},
		mounted() {
			let that = this
			const res = uni.getSystemInfoSync();
			that.$nextTick(()=>{
				const query = uni.createSelectorQuery().in(that);
				query.select('.box').boundingClientRect(data => {
					let winrate = 750/res.windowWidth;
					that.screenHeight = (res.windowHeight*winrate-data.height*winrate);
				}).exec();
			})
			this.getData()
		},
		onShow() {
			this.show = uni.getStorageSync("isMoney") ? uni.getStorageSync("isMoney"): false;
		},
		methods:{
			currencyType(type){
				return currencyType(type)
			},
			formatDate(value){
				return formatDate(value)
			},
			async getData(){
				let res = await recordCurrency({page:this.page,size:20});
				if(this.page===1&&res.data.length === 0){
					this.status = "nodata"
					return
				}
				if(this.page===1&&res.data.length > 0 && res.data.length < 20){
					this.status = "nomore"
				}
				if(res.data.length === 0){
					this.status = "nomore"
					return;
				}
				this.page++;
				this.data = this.data.concat(res.data);
			},
		}
	}
</script>

<style scoped lang="less" src="./capital.less">
</style>
